<!DOCTYPE html>


<html lang="zh-Hans">


<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    入门经典第三章之字符串（下） |  Veal&#39;s Blog
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

<link rel="alternate" href="/atom.xml" title="Veal's Blog" type="application/atom+xml">
<link href="https://cdn.bootcss.com/KaTeX/0.11.1/katex.min.css" rel="stylesheet" /></head>

</html>

<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-UVaOJ3"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  入门经典第三章之字符串（下）
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/08/06/UVaOJ3/" class="article-date">
  <time datetime="2020-08-06T01:13:43.000Z" itemprop="datePublished">2020-08-06</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E7%AE%97%E6%B3%95%E7%AB%9E%E8%B5%9B/">算法竞赛</a> / <a class="article-category-link" href="/categories/%E7%AE%97%E6%B3%95%E7%AB%9E%E8%B5%9B/cpp%E5%9F%BA%E7%A1%80/">cpp基础</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> Word count:</span>
            <span class="post-count">1.4k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> Reading time≈</span>
            <span class="post-count">5 min</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <p>在<a href="https://vealm.gitee.io/2020/07/30/UVaOJ2/">入门经典第三章之字符串（上）</a>中，介绍了cpp字符串及定义其上的运算与操作，在本篇博客中，将结合入门经典的经典例题对字符串进行应用。</p>
<a id="more"></a>
<h2 id="竖式问题"><a href="#竖式问题" class="headerlink" title="竖式问题"></a>竖式问题</h2><p><img src="https://i.loli.net/2020/08/06/wo9hxAkVOGUPBCZ.png" alt="3-3.png"></p>
<p><strong>分析</strong>：该问题可分解为两个子问题：</p>
<ul>
<li>1 竖式输出格式</li>
<li>2 判断竖式是否合法</li>
</ul>
<h3 id="竖式输出格式"><a href="#竖式输出格式" class="headerlink" title="竖式输出格式"></a>竖式输出格式</h3><p>我们使用cpp的控制符，能够用一行完成整个竖式的输出</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;iomanip&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line">cout &lt;&lt; setw(5) &lt;&lt; abc &lt;&lt; '\n' &lt;&lt; "X" &lt;&lt; setw(4) &lt;&lt; de &lt;&lt; '\n' &lt;&lt; string s(5,'-') &lt;&lt; '\n' &lt;&lt; setw(5) &lt;&lt; x &lt;&lt; '\n' &lt;&lt; setw(4) &lt;&lt; y &lt;&lt; '\n' &lt;&lt; string s(5,'-') &lt;&lt; setw(5) &lt;&lt; z &lt;&lt; endl;</span><br></pre></td></tr></table></figure>

<p>需要注意的是，setw的作用域仅限于后一个输出流</p>
<h3 id="竖式合法性"><a href="#竖式合法性" class="headerlink" title="竖式合法性"></a>竖式合法性</h3><p>我们给出判断竖式合法性的步骤：</p>
<ul>
<li>1 将 abc de x y z重定向到字符串s中</li>
<li>2 将字符串s与输入集合比较，看是否均在集合中，如是，则认为合理解，否则，跳过；</li>
</ul>
<h4 id="输出重定向到字符串"><a href="#输出重定向到字符串" class="headerlink" title="输出重定向到字符串"></a>输出重定向到字符串</h4><p>相比于c中的sprintf，我们使用cpp中的ostringstream完成输出重定向</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;sstream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"></span><br><span class="line"><span class="built_in">ostringstream</span> s;</span><br><span class="line">s &lt;&lt; abc &lt;&lt; de &lt;&lt; x &lt;&lt; y &lt;&lt; z;</span><br><span class="line"><span class="built_in">cout</span> &lt;&lt; s.str();</span><br></pre></td></tr></table></figure>

<h4 id="合法性判断"><a href="#合法性判断" class="headerlink" title="合法性判断"></a>合法性判断</h4><p>我们使用查找字符子串的find方法，遍历s的字符，考察其是否均在输入集合中</p>
<h4 id="示例代码"><a href="#示例代码" class="headerlink" title="示例代码"></a>示例代码</h4><h2 id="最长回文子串"><a href="#最长回文子串" class="headerlink" title="最长回文子串"></a>最长回文子串</h2><p><img src="https://i.loli.net/2020/08/06/3reEzOVAbvXyt8x.png" alt="3-4.png"></p>
<p>这道题目较为复杂，泛读题目发现有三个问题需要解决：</p>
<ul>
<li>1 输入输出</li>
<li>2 判断时忽略大小写及空格符号</li>
<li>3 求字母字符串中的最长回文子串</li>
</ul>
<h3 id="求回文子串"><a href="#求回文子串" class="headerlink" title="求回文子串"></a>求回文子串</h3><p>我们先考虑核心问题，求最长回文子串<br>根据题目，若字符串s[i..j]为回文子串，则有<br>$for \quad k \rightarrow 0:(j-i)$<br>$s[i+k] = s[j-k]$<br>这样的定义方式自然是简洁的，但在计算机实际判断回文串时，使用定义作为判断式则做了一半的无效运算：因为回文串是<em>中心对称</em>的，只需前半段即可。<br>因此，问题3的算法可写作</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">遍历字符串的所有子串s</span><br><span class="line">    判断字符串s是否为回文串</span><br><span class="line">    如是，判断是否更新max、记录子串位置s[i...j]</span><br></pre></td></tr></table></figure>

<p>这个算法当然是可行的，但我们是否真的需要遍历字符串的所有子串呢？我们可以进一步利用其中心对称性质，枚举回文子串的<strong>中心位置</strong>，逐步扩充为最长回文子串（回文子串的对称子串是回文子串）<br><em>需要注意的是，奇长串和偶长串的中心位置是不同的，或者可以说，偶长串的中心位置是虚拟的</em></p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 奇长串s len(s)=m</span></span><br><span class="line"><span class="keyword">for</span> k -&gt; <span class="number">0</span>:m</span><br><span class="line">    <span class="keyword">for</span> j -&gt; 合法字符串</span><br><span class="line">        <span class="keyword">if</span> s[k+j] != s[k-j]</span><br><span class="line">            flag = j<span class="number">-1</span></span><br><span class="line">            cur_len = <span class="number">2</span>*flag + <span class="number">1</span></span><br><span class="line">            <span class="keyword">if</span> cur_len &gt; max</span><br><span class="line">                max = cur_len</span><br><span class="line">                s[k-flag:k+flag]为当前最长回文串</span><br><span class="line"><span class="comment">// 偶长串</span></span><br><span class="line"><span class="keyword">for</span> k-&gt; <span class="number">0</span>:m</span><br><span class="line">    <span class="keyword">for</span> j-&gt; 合法字符串</span><br><span class="line">        <span class="keyword">if</span> s[k+j] != s[k-j+<span class="number">1</span>]</span><br><span class="line">            flag = j<span class="number">-1</span></span><br><span class="line">            cur_len = <span class="number">2</span>*flag</span><br><span class="line">            <span class="keyword">if</span> cur_len &gt; max</span><br><span class="line">                max = cur_len</span><br><span class="line">                s[k-flag+<span class="number">1</span>:k+flag]为当前最长回文子串</span><br></pre></td></tr></table></figure>

<p>解决了求回文子串的问题，我们再考虑输入问题<br>本题读入一行文字，里面包含空格，对于cin，其读取字符串流遇到空格则终止，因而不适用于本题；所幸，cpp提供的istream&amp; getline (istream&amp;  is, string&amp; str) (具体介绍见<a href="https://vealm.gitee.io/2020/07/30/UVaOJ2/#getline%E6%96%B9%E6%B3%95-%E4%BF%9D%E7%95%99%E7%A9%BA%E6%A0%BC">入门经典第三章之字符串（上）</a>)</p>
<p>我们采用预处理的方式来解决忽略大小写及原样输出的问题</p>
<h3 id="预处理"><a href="#预处理" class="headerlink" title="预处理"></a>预处理</h3><p>忽略大小写并不难，我们利用cctype提供的判断及tolower方法将字符串全部转化为小写，称此步骤得到的仅字母的字符串为预处理后字符串。<br>难点在于如何保持原样输出，此时我们需要<strong>在预处理后字符串与原字符串之间建立映射</strong>，我们<strong>使用数组p完成:数组p的下标代表预处理后字符串的index，p的内容代表原字符串的下标</strong></p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> i -&gt; <span class="number">0</span>:len(s)</span><br><span class="line">    <span class="keyword">if</span> s[i] is letter</span><br><span class="line">        <span class="keyword">if</span> s[i] is upper</span><br><span class="line">            src.append(lower(s[i]))</span><br><span class="line">        <span class="keyword">else</span></span><br><span class="line">            src.append(lower(s[i]))</span><br><span class="line">        p.append(i)</span><br></pre></td></tr></table></figure>

<h4 id="示例代码-1"><a href="#示例代码-1" class="headerlink" title="示例代码"></a>示例代码</h4><h2 id="周期串"><a href="#周期串" class="headerlink" title="周期串"></a>周期串</h2><p><img src="https://i.loli.net/2020/08/10/tQkNohgj7Z3XBRJ.png" alt="5-1-3.png"></p>
<h3 id="分析"><a href="#分析" class="headerlink" title="分析"></a>分析</h3><p>写出周期串的数学表达：<br>$$s(i) = s(i+kT) \quad \forall i \in {0,\cdots,len(s)-1} $$</p>
<p>因此，本题的思路是清晰的：我们将字符串按周期T分割为len(s)/T段，检查每段内对应位置是否相同。另外，题目要求输出最小周期，那么讨巧的办法自然是从周期1开始枚举。</p>
<p>进一步，我们考虑用取模形式对周期串进行表达<br>对于周期T，字符串s有<br>$$s(i) = s(i%T), \quad i \in {T,\cdots, len(s)-1}$$</p>
<p>这样，我们就将周期字符串的所有位置均转化到第一个周期内进行比较。</p>
<h2 id="I-O效率的讨论"><a href="#I-O效率的讨论" class="headerlink" title="I/O效率的讨论"></a>I/O效率的讨论</h2><p>IO效率讨论蛮有意思的<del>打算从文件流、重定向、cin与printf这四个方面来比较</del><br>针对字符串，还有getline、getchar方法，因此也需要从不同方法的角度来考虑，具体的测试和代码我已经做啦，参见<a href="https://gitee.com/VealM/UVaOJ/tree/master/Chapter3/textbook/iotest" target="_blank" rel="noopener">Gitee仓库</a>或<a href="https://github.com/VealM/UVaOJ/tree/master/Chapter3/textbook/iotest" target="_blank" rel="noopener">Github仓库</a>，具体的补充等我读完研究生论文再补上呜呜呜</p>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>Copyright： </strong>
          Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://vealm.gitee.io/2020/08/06/UVaOJ3/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/cpp%E5%AD%97%E7%AC%A6%E4%B8%B2/" rel="tag">cpp字符串</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2020/08/14/bign/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            大整数类设计文档
          
        </div>
      </a>
    
    
      <a href="/2020/07/30/UVaOJ2/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">入门经典第三章之字符串（上）</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "854ziDXtPQxK8dJf2vsosmzN-gzGzoHsz",
    app_key: "kV9lcyv3dVA2I6pqA4yd23p6",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
     
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2020
        <i class="ri-heart-fill heart_icon"></i> Veal
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        Powered by <a href="https://hexo.io" target="_blank">Hexo</a>
        <span class="division">|</span>
        Theme - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278599897&amp;web_id=1278599897'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="Veal&#39;s Blog"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/Me">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    
    <!--加入音乐播放器-->

    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/img/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/img/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>

<!-- Katex -->


    
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css">
        <script src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js"></script>
        
    


<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


    
  </div>
</body>

</html>